//
//  Person.m
//  SDDataTest
//
//  Created by sodao on 12-9-19.
//  Copyright (c) 2012年 sodao. All rights reserved.
//

#import "Person.h"

@implementation Person
@synthesize  isSampleInfo;
@synthesize  userID;
@synthesize  nickName;
@synthesize  headerURL;
@synthesize  address;
@synthesize  dayMCUp;
@synthesize  monthMCUp;
@synthesize  attentionArray,fansArray,favourArray,showArray;
@synthesize  mariage;
@synthesize  hasAttentioned,isBlacked;
@synthesize  sex;
@synthesize  fanListNum,attentionListNum,topicListNum,favoutListNum,showListNum,blackListNum;
@synthesize  charmQuantity,showBeanQuantity;

- (void)encodeWithCoder:(NSCoder *)aCoder{
    [super encodeWithCoder:aCoder];
    
    [aCoder encodeObject:self.userID forKey:kEncodeField_userID];
    [aCoder encodeInt:self.sex forKey:kEncodeField_sex];
    [aCoder encodeInt:self.mariage forKey:kEncodeField_mariage];
    [aCoder encodeBool:self.hasAttentioned forKey:kEncodeField_attention];
    [aCoder encodeObject:self.nickName forKey:kEncodeField_nickName];
    [aCoder encodeObject:self.headerURL forKey:kEncodeField_headerURL];
    [aCoder encodeObject:self.address forKey:kEncodeField_address];
    [aCoder encodeBool:self.isBlacked forKey:kEncodeField_isBlack];
    [aCoder encodeInt:self.dayMCUp forKey:kEncodeField_dayMC];
    [aCoder encodeInt:self.monthMCUp forKey:kEncodeField_MonthMC];
    [aCoder encodeObject:self.charmQuantity forKey:kEncodeField_charmQuantity];
    [aCoder encodeObject:self.showBeanQuantity forKey:kEncodeField_showbeanQuantity];
    
    [aCoder encodeObject:self.attentionArray forKey:kEncodeField_attentionArray];
    [aCoder encodeObject:self.fansArray forKey:kEncodeField_fansArray];
    [aCoder encodeObject:self.favourArray forKey:kEncodeField_favourArray];
    [aCoder encodeObject:self.showArray forKey:kEncodeField_showArray];

    [aCoder encodeObject:self.fanListNum forKey:kEncodeField_fanListNum];
    [aCoder encodeObject:self.attentionListNum forKey:kEncodeField_attentionListNum];
    [aCoder encodeObject:self.topicListNum forKey:kEncodeField_topicListNum];
    [aCoder encodeObject:self.favoutListNum forKey:kEncodeField_favoutListNum];
    [aCoder encodeObject:self.showListNum forKey:kEncodeField_showListNum];
    [aCoder encodeObject:self.blackListNum forKey:kEncodeField_blackListNum];
}
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        
        self.charmQuantity=[decoder decodeObjectForKey:kEncodeField_charmQuantity];
        self.showBeanQuantity=[decoder decodeObjectForKey:kEncodeField_showbeanQuantity];
        self.blackListNum = [decoder decodeObjectForKey:kEncodeField_blackListNum] ;
        self.userID = [decoder decodeObjectForKey:kEncodeField_userID];
        self.nickName = [decoder decodeObjectForKey:kEncodeField_nickName];
        self.headerURL = [decoder decodeObjectForKey:kEncodeField_headerURL];
        self.address = [decoder decodeObjectForKey:kEncodeField_address];
        self.mariage = [[decoder decodeObjectForKey:kEncodeField_mariage] intValue];
        self.isBlacked = [decoder decodeBoolForKey:kEncodeField_isBlack];
        self.hasAttentioned = [decoder decodeBoolForKey:kEncodeField_attention] ;
        self.sex = [decoder decodeIntForKey:kEncodeField_sex];
        
        self.monthMCUp = [decoder decodeIntegerForKey:kEncodeField_MonthMC];
        self.dayMCUp = [decoder decodeIntegerForKey:kEncodeField_dayMC];
        
        self.attentionArray = [decoder decodeObjectForKey:kEncodeField_attentionArray];
        self.fansArray = [decoder decodeObjectForKey:kEncodeField_fansArray];
        self.favourArray = [decoder decodeObjectForKey:kEncodeField_favourArray];
        self.showArray = [decoder decodeObjectForKey:kEncodeField_showArray];
        
        self.fanListNum = [decoder decodeObjectForKey:kEncodeField_fanListNum] ;
        self.attentionListNum = [decoder decodeObjectForKey:kEncodeField_attentionListNum] ;
        self.topicListNum = [decoder decodeObjectForKey:kEncodeField_topicListNum] ;
        self.favoutListNum = [decoder decodeObjectForKey:kEncodeField_favoutListNum] ;
        self.showListNum = [decoder decodeObjectForKey:kEncodeField_showListNum] ;

    }
    return self;
}


-(id)initWithDictionary:(NSDictionary*)info isShort:(BOOL)shortInfo{
    self = [super init];
    if (self) {
        self.isSampleInfo = shortInfo;
        self.headerURL=[info objectForKey:kEncodeField_userID];
        self.nickName=[info objectForKey:kEncodeField_nickName];
        self.userID=[info objectForKey:kEncodeField_userID];
        if (!shortInfo) {
            self.sex=[[info objectForKey:kEncodeField_sex] intValue];
            self.address=[info objectForKey:kEncodeField_address];
            self.showListNum=[info objectForKey:kEncodeField_showListNum];
            self.fanListNum=[info objectForKey:kEncodeField_fanListNum];
            self.attentionListNum=[info objectForKey:kEncodeField_attentionListNum];
            self.topicListNum=[info objectForKey:kEncodeField_topicListNum];
            self.favoutListNum=[info objectForKey:kEncodeField_fanListNum];
            self.charmQuantity=[info objectForKey:kEncodeField_charmQuantity];
            self.showBeanQuantity=[info objectForKey:kEncodeField_showbeanQuantity];
            self.hasAttentioned=[[info objectForKey:kEncodeField_attention] boolValue];
            self.isBlacked=[[info objectForKey:kEncodeField_isBlack] boolValue];
            self.mariage=[[info objectForKey:kEncodeField_mariage] intValue];
        }
    }
    return self;
}
-(id)initWithData:(NSData*)data isShort:(BOOL)shortInfo{
    return [self initWithDictionary:[self parserString:[self changeNetDataToString:data]] isShort:shortInfo];
}
-(void)updateInfoByDictionary:(NSDictionary*)dictionary{
    self.isSampleInfo = NO;
    self.sex=[[dictionary objectForKey:kEncodeField_sex] intValue];
    self.address=[dictionary objectForKey:kEncodeField_address];
    self.showListNum=[dictionary objectForKey:kEncodeField_showListNum];
    self.fanListNum=[dictionary objectForKey:kEncodeField_fanListNum];
    self.attentionListNum=[dictionary objectForKey:kEncodeField_attentionListNum];
    self.topicListNum=[dictionary objectForKey:kEncodeField_topicListNum];
    self.favoutListNum=[dictionary objectForKey:kEncodeField_fanListNum];
    self.charmQuantity=[dictionary objectForKey:kEncodeField_charmQuantity];
    self.showBeanQuantity=[dictionary objectForKey:kEncodeField_showbeanQuantity];
    self.hasAttentioned=[[dictionary objectForKey:kEncodeField_attention] boolValue];
    self.isBlacked=[[dictionary objectForKey:kEncodeField_isBlack] boolValue];
    self.mariage=[[dictionary objectForKey:kEncodeField_mariage] intValue];
}
-(void)updateInfoByData:(NSData*)data{
    [self updateInfoByDictionary:[self parserString:[self changeNetDataToString:data]]];
}
-(void)dealloc{
    [super dealloc];
    [self.userID release];
    [self.nickName release];
    [self.headerURL release];
    [self.address release];
    
    [self.attentionArray removeAllObjects];
    [self.fansArray removeAllObjects];
    [self.favourArray removeAllObjects];
    [self.showArray removeAllObjects];
    [self.attentionArray release];
    [self.fansArray release];
    [self.favourArray release];
    [self.showArray release];
    
    [self.fanListNum  release];
    [self.attentionListNum release];
    [self.topicListNum release];
    [self.favoutListNum release];
    [self.showListNum release];
    [self.blackListNum release];
    [self.charmQuantity release];
    [self.showBeanQuantity release];
}
@end
